package com.bruce.starts.demo.commonerror.test;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @author luotuan
 * @Description
 * @create 2021-05-13 14:43
 **/
public class PracticeDemo {
    public static void main(String[] args) {
//        String name = "bruce";
//        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append(String.format("%-10s",name).replace(' ','_'));
//        System.out.println(stringBuilder.toString());
//        outloopB:
//        for(int i=0;i<10;i++){
//            System.out.println("i="+i);
//            outloopA:
//            for(int j=0;j<10;j++){
//                System.out.println("j="+j);
////                if(j==0){
////                    break ;
////                }
//            }
//        }
        List<B> result =  IntStream.rangeClosed(0,4).mapToObj((i)->new B(BigDecimal.valueOf(0)))
                .collect(Collectors.toList());
        result.forEach((r)-> System.out.println("年龄"+r.getAge()));
        BigDecimal avgAge = result.stream().map(B::getAge).reduce(BigDecimal.ZERO,BigDecimal::add).divide(BigDecimal.valueOf(result.size()), 2, BigDecimal.ROUND_HALF_UP);
        System.out.println(String.format("平均年龄:%s",avgAge.toString()));
    }
}
class B{
    BigDecimal age;

    public B(BigDecimal age) {
        this.age = age;
    }

    public BigDecimal getAge() {
        return age;
    }

    public B setAge(BigDecimal age) {
        this.age = age;
        return this;
    }
}
